package com.lagou.webwork.servlet.classes; /**
 * @author sjp
 * @date 2021/6/7 11:28
 * @description
 */

import com.alibaba.fastjson.JSON;
import com.lagou.webwork.model.Result;
import com.lagou.webwork.service.ClassService;
import com.lagou.webwork.service.StudentService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "DeleteClassListServlet", value = "/deleteClassList")
public class DeleteClassListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        String idListJson = request.getParameter("idList");
        List<Integer> idList = JSON.parseArray(idListJson, Integer.class);


        //创建Service对象，执行addStudent方法添加学生信息
        ClassService service = new ClassService();
        Result<Integer> result = service.deleteClassList(idList);

        //设置编码格式
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=utf-8");

        //输出给前端
        PrintWriter writer = response.getWriter();
        writer.print(result.toString());
        writer.flush();
    }
}
